<?php

Raise::load('core.RaiseObject');

/**
 * RaiseValidator abstract class
 * represents an abstract validator
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.validator
 * @abstract
 * @since 1.2
 */
abstract class RaiseValidator extends RaiseObject {

    /**
     * The error message associated with this validator
     * @var string
     */
    protected $errorMessage;

    /**
     * A flag indicating whether or not the value validated is valid or not.
     * @var boolean
     */
    protected $isValid = false;

    /**
     * A flag set whether the validation has been done or not
     * @var boolean
     */
    protected $hasValidated = false;

    /**
     * Return the result of the validation.
     * TRUE for success, FALSE for failure.
     * @return boolean
     */
    public function isValid(){
        return $this->isValid;
    }

    /**
     * Query whether or not the validation has been done.
     * @return boolean
     */
    public function hasValidated(){
        return $this->hasValidated;
    }

    /**
     * Get or set the error message associated with this validator
     * @param string $msg (optional) When set, the error message will be set to this value.
     * @return string
     */
    public function errorMessage($msg = false){
        if(func_num_args() == 1){
            $this->errorMessage = $msg;
        }
        return $this->errorMessage;
    }

    /**
     * Do the validation with the value to validate.
     * @param mixed $value
     */
    public function validate($value){
        $this->hasValidated = true;
    }
    
}
